package flexcommon.utils
{
	/**
	 * <p>Class containing some static character utility methods that evaluate
	 * the associated ASCII code of a character and determine in which category
	 * it falls in.</p>
	 * 
	 * <p>The ASCII chart can be found at the following location:
	 * <code>http://en.wikipedia.org/wiki/Ascii_table</code></p>
	 *
	 * <p>Author: Dimitrios Gianninas</p>
	 */
	public class CharacterUtils
	{

		/**
		 * Determines if a particuliar character is a control character.
		 * A control character is one of the first 32 characters in the ASCII chart.
		 * 
		 * @param the character to evaluate
		 * @return TRUE if a control character, FALSE otherwise
		 */
		public static function isControl( c:String ):Boolean 
		{
			return c != null && ( c.charCodeAt(0) >= 0 && c.charCodeAt(0) <= 31 );
		}
    
    /**
     * Determines if a particuliar character is the space character.
     * A space character is determined to be according to the ASCII
     * chart, character 32 (space).
     * 
     * @param the character to evaluate
     * @return TRUE if a space character, FALSE otherwise
     */
    public static function isSpace( c:String ):Boolean 
    {
      return c.charCodeAt(0) == 32;
    }
	
		/**
		 * Determines if a particuliar character is a whitespace character.
		 * A whitespace character is determined to be according to the ASCII
		 * chart, characters: 0 (null), 10 (linefeed), 13 (return) or 32 (space).
		 * 
		 * @param the character to evaluate
		 * @return TRUE if a whitespace character, FALSE otherwise
		 */
		public static function isWhiteSpace( c:String ):Boolean 
		{
			return ( c.charCodeAt(0) == 0
					|| c.charCodeAt(0) == 10
					|| c.charCodeAt(0) == 13
					|| c.charCodeAt(0) == 32 );
		}
	
		/**
		 * Determines if a particuliar character is a punctuation character.
		 * Meaning a printable character that is not alphabetic or numeric.
		 * 
		 * @param the character to evaluate
		 * @return TRUE if a punctuation character, FALSE otherwise
		 */
		public static function isPunctuation( c:String ):Boolean 
		{
			return ( (c.charCodeAt(0) >= 32 && c.charCodeAt(0) <= 47)
					|| (c.charCodeAt(0) >= 58 && c.charCodeAt(0) <= 64)
					|| (c.charCodeAt(0) >= 91 && c.charCodeAt(0) <= 96)
					|| (c.charCodeAt(0) >= 123 && c.charCodeAt(0) <= 126) );
		}
	
		/**
		 * Determines if a particuliar character is an alphabetic character,
		 * either uppercase or lowercase.
		 * 
		 * @param the character to evaluate
		 * @return TRUE if a alphabetic character, FALSE otherwise
		 */
		public static function isAlphabetic( c:String ):Boolean 
		{
			return ( (c.charCodeAt(0) >= 65 && c.charCodeAt(0) <= 90)
					|| (c.charCodeAt(0) >= 97 && c.charCodeAt(0) <= 122) );
		}
		
		/**
		 * Determines if a particuliar character is an alphabetic or numeric character.
		 * This method is a combination of isAlphabetic() OR isNumeric().
		 * 
		 * @param the character to evaluate
		 * @return TRUE if a alphanumeric character, FALSE otherwise
		 * 
		 * @see isAlphabetic()
		 * @see isNumeric()
		 */
		public static function isAlphaNumeric( c:String ):Boolean 
		{
			return ( isAlphabetic( c ) || isNumeric( c ) );
		}
	
		/**
		 * Determines if a particuliar character is a numeric character.
		 * 
		 * @param the character to evaluate
		 * @return TRUE if a numeric character, FALSE otherwise
		 */
		public static function isNumeric( c:String ):Boolean 
		{
			return ( c.charCodeAt(0) >= 48 && c.charCodeAt(0) <= 57 );
		}
	}
}